using System.Windows.Media;
using Brjnk.Common;
using Brjnk.GpxExplorer.Workspace.Searching;

namespace Brjnk.GpxExplorer.Workspace
{
    /// <summary>
    /// </summary>
    public class CoordinatesFromClipboard : ItemFromClipboard
    {
        private GpsCoordinates coordinates;

        public CoordinatesFromClipboard(GpsCoordinates coordinates, string waypointName)
        {
            this.coordinates = coordinates;
            this.WaypointName = waypointName;
        }

        public GpsCoordinates Coordinates { get { return coordinates; } }

        private string waypointName;

        public string WaypointName
        {
            get { return waypointName; }
            set { waypointName = value; OnPropertyChanged("WaypointName"); }
        }

        private bool createWaypoint;

        public bool CreateWaypoint
        {
            get { return createWaypoint; }
            set { createWaypoint = value; OnPropertyChanged("CreateWaypoint"); }
        }

        private bool search;

        public bool Search
        {
            get { return search; }
            set { search = value; OnPropertyChanged("Search"); }
        }

        private Color searchColor;

        public Color SearchColor
        {
            get { return searchColor; }
            set { searchColor = value; OnPropertyChanged("SearchColor"); }
        }

        public override void Execute(DataModel data, SearchService searchService)
        {
            if (CreateWaypoint)
            {
                var waypoint = new Brjnk.GpxExplorer.Data.WaypointDefault();
                waypoint.Position = coordinates;
                waypoint.Name = waypointName;
                data.Waypoints.Add(new ViewModel.WaypointVM(waypoint));
            }
            if (Search)
            {
                searchService.SearchedItems.Add(new SearchPositionRequest()
                {
                    Position = coordinates,
                    Color1 = SearchColor,
                    SearchInGaps = SearchService.DefaultSearchInGaps,
                    MaxDistance = SearchService.DefaultLimit,
                    ShowAgainDistance = SearchService.DefaultSearchAgainLimit
                });
            }
        }
    }
}